#ifndef __I2C_H
#define __I2C_H

#include "stm32f4xx.h"  


#define I2C_ACK     0
#define I2C_NACK    1

#define I2C_PORT    GPIOE
#define I2C_CLK     RCC_AHB1Periph_GPIOE
#define I2C_SDA     GPIO_Pin_0
#define I2C_SCL     GPIO_Pin_1

#define SDA(x) (x) ? (I2C_PORT->ODR |= I2C_SDA) : \
                        (I2C_PORT->ODR &= ~I2C_SDA) 
#define SCL(x) (x) ? (I2C_PORT->ODR |= I2C_SCL) : \
                        (I2C_PORT->ODR &= ~I2C_SCL) 

#define SDA_RELEASE() SDA(1)
#define SDA_LOCK()    SDA(0)
#define SCL_RELEASE() SCL(1)
#define SCL_LOCK()    SCL(0)

#define READ_SDA    (I2C_PORT->IDR & I2C_SDA)


void i2c_init(void);
void i2c_start(void);
void i2c_stop(void);
void i2c_send_ack(void);
void i2c_send_nack(void);
uint8_t i2c_wait_ack(void);
void i2c_send_byte(uint8_t byte);
uint8_t i2c_recv_byte(void);
int i2c_send_mutlibyte(uint8_t dev_addr,uint8_t *buff,uint8_t size);

#endif // __I2C_H